<template>
  <div class="popularlist">
    <p>最受欢迎的电影</p>
    <div class="warpper-list-parent">
      <ul class="warpper-list-child">
        <li v-for="item of ratedList" :key="item._id">
          <img :src="item.imgUrl" alt="" />
          <span v-if="item.score">观众评分 {{ item.score }}</span>
          <span v-else>{{ item.wishNum }}人想看</span>
          <p>{{ item.title }}</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { getPopularDataApi } from "../../utils/api";
import BetterScroll from "better-scroll";
export default {
  data() {
    return {
      ratedList: [],
    };
  },
  mounted() {
    this.getPopular();
  },
  methods: {
    async getPopular() {
      const res = await getPopularDataApi();
      this.ratedList = res.result;
      await this.$nextTick();
      new BetterScroll(".warpper-list-parent", {
        scrollX: true,
        scrollY: false,
        click: true,
      });
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../assets/css/var.less";
.popularlist {
  height: 200px;
  padding: 12px 15px;
  background: #fff;
  p {
    height: 19px;
    margin-bottom: 12px;
    font-size: @s-font;
  }
  .warpper-list-parent {
    position: fixed;
    width: 100%;
    height: 146px;
    overflow: hidden;
  }
  .warpper-list-child {
    display: inline-flex;
    height: 146px;
    li {
      width: 85px;
      position: relative;
      margin-right: 15px;
      font-size: @xs-font;
      img {
        width: 85px;
        height: 115px;
      }
      p {
        font-weight: 900;
        width: 100%;
        height: 17px;
        line-height: 17px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
      }
      span {
        width: 100%;
        color: #faaf00;
        font-size: @xxs-font;
        font-weight: 600;
        margin-left: 2px;
        position: absolute;
        left: 0;
        bottom: 32px;
        line-height: 16px;
        background: linear-gradient(to top, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0));
      }
    }
  }
}
</style>
